' ########################################################################################
' #
' #	NAME:  hobbbit_lp_free_space_check.vbs
' #	AUTHOR: Joe Birney - FJB047
' #	GROUP:  BMS EIT
' #	DATE CREATED: 05/06/2010
' #
' # PROGRAM PURPOSE:	
' #   This script will do a very quick check and report back on the if the status of the L/P drives based on the 
' #   Warning and Critical sizes values (in Gb) it was pased)
' # 
' #   The proper way to use this script would be:
' #   cscript lp_free_space_check.vbs WARNING_SIZE CTRICIAL SIZE PDRIVE_UNC  LDRIVE_UNC GBUSED_SWITCH //nologo
' # 
' #   And then parse the standard output for the desired data. 
' #
' # 
' #	ACKNOWLEDGEMENTS: 
' #
' #	REVISIONS:
' #	REV		DATE		INITIALS	DESCRIPTION
' #	1.0		05/06/2010	Jb		First version
' #	1.1		06/08/2010	Jb		Updated to handle UNC paths, to do checking for both Precentage as well as GB and to return Free,Total,Used and %Usage for each drive
' #	1.2		10/04/2010	Jb		Used INT () around var1/2 when doing compare if GB were NOT used
' #########################################################################################

'====================================================================================
' Vars and Setup
'====================================================================================
Dim re,LFree,PFree,PFreeGB,LFreeGB,LTotal,PTotal,PTotalGB,LTotalGB,LUsage,PUsedGB,LUsedGB
Set re = New RegExp
Dim ArgObj, var1, var2,LDRIVE,PDRIVE,GBUSED
Set ArgObj = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")

   
'Get Vars
var1 = ArgObj(0)
var2 = ArgObj(1)
PDRIVE = ArgObj(2)
LDRIVE = ArgObj(3)
GBUSED = ArgObj(4)


'====================================================================================
' Begin main code
'====================================================================================

' - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Get L Drive Free Space
Set d = fso.GetDrive(fso.GetDriveName(LDRIVE))
LFree = d.FreeSpace
LTotal = d.TotalSize
LFreeGB = FormatNumber(LFree / 1073741824,2,,,0)
LTotalGB = FormatNumber(LTotal / 1073741824,2,,,0)
LUsedGB = FormatNumber((LTotal - LFree) / 1073741824,2,,,0)
LUsage = FormatNumber(((LTotal - LFree) /LTotal * 100),0)

if GBUSED = "YES" then
	var1 = ArgObj(0) * 1024 * 1024 * 1024
	var2 = ArgObj(1) * 1024 * 1024 * 1024
	if (LFree > var1 ) Then
	  LSTATUS = "GREEN"
	elseif (LFree <= var2 ) Then
	  LSTATUS = "RED"
	else 
	  LSTATUS = "YELLOW"
	end if
else
	if (int(LUsage) => int(var2) ) Then
	  LSTATUS = "RED"
	elseif (int(LUsage) < int(var1) ) Then
	  LSTATUS = "GREEN"
	else 
	  LSTATUS = "YELLOW"
	end if
end if
LUsage = FormatPercent((LTotal - LFree)/LTotal,0)


' - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Get P Drive Free Space
Set d = fso.GetDrive(fso.GetDriveName(PDRIVE))
PFree = d.FreeSpace
PTotal = d.TotalSize
PFreeGB = FormatNumber(PFree  / 1073741824,2,,,0)
PTotalGB = FormatNumber(PTotal / 1073741824,2,,,0)
PUsedGB = FormatNumber((PTotal - PFree) / 1073741824,2,,,0)
PUsage = FormatNumber(((PTotal - PFree)/PTotal * 100),0)

if GBUSED = "YES" then
	var1 = ArgObj(0) * 1024 * 1024 * 1024
	var2 = ArgObj(1) * 1024 * 1024 * 1024
	if (PFree > var1 ) Then
	  PSTATUS = "GREEN"
	elseif (PFree <= var2 ) Then
	  PSTATUS = "RED"
	else 
	  PSTATUS = "YELLOW"
	end if
else
	if (int(PUsage) => int (var2) ) Then
	  PSTATUS = "RED"
	elseif (int(PUsage) < int (var1) ) Then
	  PSTATUS = "GREEN"
	else 
	  PSTATUS = "YELLOW"
	end if
end if
PUsage = FormatPercent((PTotal - PFree)/PTotal,0)

	
' - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Report results here
Wscript.StdOut.Writeline PSTATUS & "," & LSTATUS  & "," & PFreeGB  & "," & LFreeGB &"," & PTotalGB  & "," & LTotalGB & "," & PUsage  & "," & LUsage & "," & PUsedGB  & "," & LUsedGB